home *** CD-ROM | disk | FTP | other *** search
- package koala.dynamicjava.classinfo;
-
- import java.lang.reflect.Modifier;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import koala.dynamicjava.tree.ClassDeclaration;
- import koala.dynamicjava.tree.FieldDeclaration;
- import koala.dynamicjava.tree.InterfaceDeclaration;
- import koala.dynamicjava.tree.MethodDeclaration;
- import koala.dynamicjava.tree.TypeDeclaration;
-
- public class TreeClassInfo implements ClassInfo {
- private static final String DECLARING_CLASS = "declaringClass";
- public static final String ANONYMOUS_DECLARING_CLASS = "anonymousDeclaringClass";
- private static final String TREE_VISITED = "treeVisited";
- private TypeDeclaration classTree;
- private ClassFinder classFinder;
- private int dimension;
- private String name;
- private ClassInfo superclass;
- private boolean interfaceInfo;
- private ClassInfo[] interfaces;
- private Map fields = new HashMap();
- private Map methods = new HashMap();
- private List constructors = new LinkedList();
- private List classes = new LinkedList();
- private boolean compilable = true;
- private int methodCount;
-
- public Class getJavaClass() {
- throw new IllegalStateException();
- }
-
- public TypeDeclaration getTypeDeclaration() {
- return this.classTree;
- }
-
- public ClassFinder getClassFinder() {
- return this.classFinder;
- }
-
- public boolean isCompilable() {
- return this.compilable;
- }
-
- public void setCompilable(boolean var1) {
- this.compilable = var1;
- }
-
- public ClassInfo getDeclaringClass() {
- return this.dimension == 0 ? (ClassInfo)this.classTree.getProperty("declaringClass") : null;
- }
-
- public ClassInfo getAnonymousDeclaringClass() {
- return this.dimension == 0 ? (ClassInfo)this.classTree.getProperty("anonymousDeclaringClass") : null;
- }
-
- public int getModifiers() {
- return this.dimension == 0 ? this.classTree.getAccessFlags() : 1;
- }
-
- public String getName() {
- return this.name;
- }
-
- public ClassInfo getSuperclass() {
- if (this.superclass == null) {
- if (this.interfaceInfo) {
- this.superclass = this.lookupClass("java.lang.Object");
- } else {
- ClassDeclaration var1 = (ClassDeclaration)this.classTree;
- this.superclass = this.lookupClass(var1.getSuperclass(), this.getDeclaringClass());
- }
- }
-
- return this.superclass;
- }
-
- public ClassInfo[] getInterfaces() {
- if (this.interfaces == null) {
- if (this.dimension > 0) {
- this.interfaces = new ClassInfo[]{this.lookupClass("java.lang.Cloneable"), this.lookupClass("java.io.Serializable")};
- } else {
- List var1 = this.classTree.getInterfaces();
- if (var1 != null) {
- this.interfaces = new ClassInfo[var1.size()];
- Iterator var2 = var1.iterator();
-
- String var4;
- for(int var3 = 0; var2.hasNext(); this.interfaces[var3++] = this.lookupClass(var4, this.getDeclaringClass())) {
- var4 = (String)var2.next();
- }
- } else {
- this.interfaces = new ClassInfo[0];
- }
- }
- }
-
- return (ClassInfo[])this.interfaces.clone();
- }
-
- public FieldInfo getField(FieldDeclaration var1) {
- return (TreeFieldInfo)this.fields.get(var1.getName());
- }
-
- public FieldInfo[] getFields() {
- if (this.dimension != 0) {
- return new FieldInfo[0];
- } else {
- Set var1 = this.fields.keySet();
- Iterator var2 = var1.iterator();
- FieldInfo[] var3 = new FieldInfo[var1.size()];
-
- for(int var4 = 0; var2.hasNext(); var3[var4++] = (FieldInfo)this.fields.get(var2.next())) {
- }
-
- return var3;
- }
- }
-
- public ConstructorInfo[] getConstructors() {
- if (this.dimension != 0) {
- return new ConstructorInfo[0];
- } else {
- Iterator var1 = this.constructors.iterator();
- ConstructorInfo[] var2 = new ConstructorInfo[this.constructors.size()];
-
- for(int var3 = 0; var1.hasNext(); var2[var3++] = (ConstructorInfo)var1.next()) {
- }
-
- return var2;
- }
- }
-
- public MethodInfo getMethod(MethodDeclaration var1) {
- Set var2 = this.methods.keySet();
- Iterator var3 = var2.iterator();
-
- while(var3.hasNext()) {
- for(TreeMethodInfo var6 : (List)this.methods.get(var3.next())) {
- if (var6.getMethodDeclaration() == var1) {
- return var6;
- }
- }
- }
-
- throw new IllegalArgumentException();
- }
-
- public MethodInfo[] getMethods() {
- if (this.dimension != 0) {
- return new MethodInfo[0];
- } else {
- MethodInfo[] var1 = new MethodInfo[this.methodCount];
- Iterator var2 = this.methods.values().iterator();
- int var3 = 0;
-
- while(var2.hasNext()) {
- for(Iterator var4 = ((List)var2.next()).iterator(); var4.hasNext(); var1[var3++] = (MethodInfo)var4.next()) {
- }
- }
-
- return var1;
- }
- }
-
- public ClassInfo[] getDeclaredClasses() {
- if (this.dimension != 0) {
- return new ClassInfo[0];
- } else {
- Iterator var1 = this.classes.iterator();
- ClassInfo[] var2 = new ClassInfo[this.classes.size()];
-
- for(int var3 = 0; var1.hasNext(); var2[var3++] = (ClassInfo)var1.next()) {
- }
-
- return var2;
- }
- }
-
- public ClassInfo getArrayType() {
- return new TreeClassInfo(this);
- }
-
- public boolean isInterface() {
- return this.classTree instanceof InterfaceDeclaration;
- }
-
- public boolean isArray() {
- return this.dimension > 0;
- }
-
- public boolean isPrimitive() {
- return false;
- }
-
- public ClassInfo getComponentType() {
- if (!this.isArray()) {
- throw new IllegalStateException();
- } else {
- TreeClassInfo var1 = new TreeClassInfo(this.classTree, this.classFinder);
-
- for(int var2 = 0; var2 < this.dimension - 1; ++var2) {
- var1 = new TreeClassInfo(var1);
- }
-
- return var1;
- }
- }
-
- public boolean equals(Object var1) {
- return var1 != null && var1 instanceof ClassInfo ? this.getName().equals(((ClassInfo)var1).getName()) : false;
- }
-
- private String fullName() {
- ClassInfo var2 = (ClassInfo)this.classTree.getProperty("declaringClass");
- String var1;
- if (var2 != null) {
- var1 = var2.getName() + "$";
- } else {
- var1 = this.classFinder.getCurrentPackage();
- if (!var1.equals("")) {
- var1 = var1 + ".";
- }
- }
-
- return var1 + this.classTree.getName();
- }
-
- private ClassInfo lookupClass(String var1) {
- try {
- return this.classFinder.lookupClass(var1);
- } catch (ClassNotFoundException var3) {
- throw new NoClassDefFoundError(var3.getMessage());
- }
- }
-
- private ClassInfo lookupClass(String var1, ClassInfo var2) {
- try {
- return var2 != null ? this.classFinder.lookupClass(var1, var2) : this.classFinder.lookupClass(var1);
- } catch (ClassNotFoundException var4) {
- throw new NoClassDefFoundError(var4.getMessage());
- }
- }
-
- private int getNestingLevel() {
- int var1 = -1;
-
- for(Object var2 = this; !Modifier.isStatic(((ClassInfo)var2).getModifiers()) && (var2 = ((ClassInfo)var2).getDeclaringClass()) != null; ++var1) {
- }
-
- return var1;
- }
-
- // $FF: synthetic method
- static TypeDeclaration access$0(TreeClassInfo var0) {
- return var0.classTree;
- }
-
- // $FF: synthetic method
- static String access$1() {
- return TREE_VISITED;
- }
-
- // $FF: synthetic method
- static int access$2(TreeClassInfo var0) {
- return var0.getNestingLevel();
- }
-
- // $FF: synthetic method
- static List access$3(TreeClassInfo var0) {
- return var0.constructors;
- }
-
- // $FF: synthetic method
- static String access$4() {
- return DECLARING_CLASS;
- }
-
- // $FF: synthetic method
- static ClassFinder access$5(TreeClassInfo var0) {
- return var0.classFinder;
- }
-
- // $FF: synthetic method
- static List access$6(TreeClassInfo var0) {
- return var0.classes;
- }
-
- // $FF: synthetic method
- static Map access$7(TreeClassInfo var0) {
- return var0.fields;
- }
-
- // $FF: synthetic method
- static Map access$8(TreeClassInfo var0) {
- return var0.methods;
- }
-
- // $FF: synthetic method
- static int access$9(TreeClassInfo var0) {
- return var0.methodCount;
- }
-
- // $FF: synthetic method
- static void access$10(TreeClassInfo var0, int var1) {
- var0.methodCount = var1;
- }
-
- public TreeClassInfo(TypeDeclaration var1, ClassFinder var2) {
- this.classFinder = var2;
- this.classTree = var1;
- this.name = this.fullName();
- this.interfaceInfo = var1 instanceof InterfaceDeclaration;
- MembersVisitor var10000 = new MembersVisitor;
- if (this == null) {
- throw null;
- } else {
- var10000.<init>(this);
- this.classTree.setProperty("treeVisited", (Object)null);
- }
- }
-
- public TreeClassInfo(TreeClassInfo var1) {
- this.classFinder = var1.classFinder;
- this.classTree = var1.classTree;
- this.dimension = var1.dimension + 1;
- this.name = "[" + (var1.isArray() ? var1.getName() : "L" + var1.getName() + ";");
- MembersVisitor var10000 = new MembersVisitor;
- if (this == null) {
- throw null;
- } else {
- var10000.<init>(this);
- }
- }
- }
-